#include <iostream>

using namespace std;

void swap(int &a, int &b){
	int t = a;
	a = b;
	b = t;
}
int& nextIdx(){
	// 静态变量只会初始化一次
	static int count = 0;
	count++;
	return count;
}
// 使用引用交换 数字
int main(){
	
	int a = 4;
	int b = 13;
	
	cout << "a = " << a << endl;
	cout << "b = " << b << endl;
	
	swap(a, b);
	
	cout << "after swap:" << endl;
	cout << "a = " << a << endl;
	cout << "b = " << b << endl;
	
	
	cout << "nextIdx = " << nextIdx() << endl;
	cout << "nextIdx = " << nextIdx() << endl;
	// 返回值是引用的函数 可以作为左值 相当于给 返回的引用变量赋值，省去了一个变量
	nextIdx() = 9;
	cout << "nextIdx = " << nextIdx() << endl;
}